package com.fatcat.easybuy.pojo;

import lombok.NonNull;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author 李开辰
 * @since 2025/9/19 09:10
 */
public class EasyBuyShoppingCart implements Serializable {
    @NotNull
    private Long productId;
    private String productName;
    private String fileName;
    @NotNull
    private Integer quantity;
    @NotNull
    private Double price;
    private Double cost;
    //时间分数
    private Long score;

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Double getCost() {
        return cost;
    }

    public void setCost(Double cost) {
        this.cost = cost;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Object price) {
        if (price instanceof Number) {
            this.price = ((Number) price).doubleValue();
        } else if (price instanceof String) {
            this.price = Double.parseDouble((String) price);
        }
        // 自动计算cost
        if (this.quantity != null) {
            this.cost = this.price * this.quantity;
        }
    }

    public Long getScore() {
        return score;
    }

    public void setScore(Long score) {
        this.score = score;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public String toString() {
        return "EasyBuyCarProduct{" +
                "productId=" + productId +
                ", productName='" + productName + '\'' +
                ", quantity=" + quantity +
                ", cost=" + cost +
                '}';
    }
}
